package com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext;

import com.taowan.xunbaozl.morning_speak.design_pattern.day10.Command;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 杨观回 on 2016/3/3 0003.
 */
public class CommandExector {
    private List<Command> commandList;

    public CommandExector() {
        this.commandList = new ArrayList<>();
    }

    public void addCommand(Command command) {
        this.commandList.add(command);
    }

    public void removeCommand(Command command) {
        this.commandList.remove(command);
    }

    public void execCommands() {
        for (Command command : commandList) {
            command.exec();
        }
        commandList.clear();
    }
}
